package com.yunc.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunc.modules.sys.entity.SysSchedule;
import com.yunc.modules.sys.mapper.SysScheduleMapper;
import com.yunc.modules.sys.service.ISysScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 日常计划
 *
 * @author congcong tao
 * @date 2019/1/18 16:41
 */
@Service("sysScheduleService")
public class SysScheduleServiceImpl extends ServiceImpl<SysScheduleMapper, SysSchedule> implements ISysScheduleService {

    @Autowired
    private SysScheduleMapper sysScheduleMapper;

    @Override
    @Transactional(rollbackFor = {RuntimeException.class})
    public boolean saveSchedule(SysSchedule schedule) {
        QueryWrapper<SysSchedule> ew = new QueryWrapper<>();
        ew.eq("day", schedule.getDay());
        boolean removeFlag = this.remove(ew);
        if (removeFlag) {
            return this.save(schedule);
        }
        return removeFlag;
    }
}
